var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    _num: 0,
    catIds:'',
    firstCatId:''
  },
  firstId:'',
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    wx.request({
      url: app.globalData.url+'getAllFristCategory',
      data: '',
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'POST',
      success: function (res) {       
        that.setData({
          catName: res.data.object,
        })
        that.firstId = res.data.object[0].catId
        if (res.data.object[0].catId == 1){
          const catId = 1;
          wx.request({
            url: app.globalData.url+'getSecondcCategoriesByParentId',
            data: {
              parentId: catId
            },
            method: 'GET',
            header: {
              'Accept': 'application/json'
            },
            success: function (res) {
              that.setData({
                secondCatName: res.data.object,
              })
            },
            fail: function (res) { },
            complete: function (res) { },
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })  
  },
  commodityClassifyItem:function(e){
    var that = this;
    const secondCatId = e.currentTarget.dataset.secondcatid
    const index = e.currentTarget.dataset.index
    const firstCatId = this.data.firstCatId
    console.log(secondCatId+','+index+','+firstCatId)
    if (firstCatId == ''){
      const firstCatId = that.firstId
      wx.navigateTo({
        url: '../businessItem/businessItem?secondCatId=' + secondCatId + '&firstCatId=' + firstCatId,
      })
    }else{
      wx.navigateTo({
        url: '../businessItem/businessItem?secondCatId=' + secondCatId + '&firstCatId=' + firstCatId,
      }) 
    }
  },
  shoppingCar:function(){
    wx.navigateTo({
      url: '../shoppingCar/shoppingCar',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  secondScreen:function(){
    
  },
  firstOne:function(e){
    var that = this;
    var catId = e.currentTarget.dataset.id;
    this.data.firstCatId = e.currentTarget.dataset.id
    wx.request({
      url: app.globalData.url+'getSecondcCategoriesByParentId',
      data: {
        parentId: catId
      },
      method: 'GET',
      header: {
        'Accept': 'application/json'
      },
      success: function(res) {
        that.setData({
          secondCatName: res.data.object,
        })
      },
      fail: function(res) {},
      complete: function(res) {},
    })
    this.setData({
      _num: e.currentTarget.dataset.num
    })
  },

})